package uml;

import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.Font;
import java.awt.LayoutManager;
import java.awt.Panel;
import java.awt.TextArea;

import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.border.Border;
import javax.swing.border.TitledBorder;

import uml.util.listeners.DragListener;
import uml.view.ClassFormatter_View;
import uml.view.UMLContainerView;
import uml.view.factory.ContainerFactory;

class Driver
{
	public static final Color JTEXTAREA_BG_COLOR = Color.GRAY;
	public static final Color UMLCONTAINER_BG_COLOR = Color.GREEN;
	public static final Color WINDOW_BG_COLOR = Color.WHITE;
	public static final int TEXTAREACOUNT = 3;

	public static void main (String[] args)
	{
		JFrame mainWindow = initWindow ();
		Container pane = mainWindow.getContentPane ();
		//pane.setLayout (new BoxLayout (pane, BoxLayout.));
		UMLContainerView umlContainer = initContainer ();
		UMLContainerView umlInterface = ContainerFactory.createInterfaceView ();
		UMLContainerView umlClass = ContainerFactory.createClassView ();
		pane.add (umlContainer);
		pane.add (umlInterface);
		pane.add (umlClass);
		ClassFormatter_View formatter = initFormatter ();
		formatter.setContainer (umlContainer);
		formatter.setFontBold ();
		mainWindow.setVisible (true);
	}

	public static JFrame initWindow ()
	{
		JFrame mainWindow = new JFrame ("UML Diagram Builder");
		mainWindow.setSize (new Dimension (600, 600));
		mainWindow.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
		Container pane = mainWindow.getContentPane ();
		pane.setBackground (WINDOW_BG_COLOR);
		pane.setLayout (new FlowLayout ());
		return mainWindow;
	}

	public static ClassFormatter_View initFormatter ()
	{
		ClassFormatter_View formatter = new ClassFormatter_View ();
		return formatter;
	}

	public static UMLContainerView initContainer ()
	{
		UMLContainerView container = new UMLContainerView ();
		container.setSize (100, 100);
		container.addDragListener (new DragListener (container));
		BoxLayout layout = new BoxLayout (container, BoxLayout.Y_AXIS);
		Border b = BorderFactory.createTitledBorder (BorderFactory.createEtchedBorder (), "test", TitledBorder.CENTER,
				TitledBorder.TOP);
		container.setBorder (b);
		container.setLayout (layout);
		container.setBackground (UMLCONTAINER_BG_COLOR);
		addJTextAreas (container);
		return container;
	}

	public static void addJTextAreas (UMLContainerView container)
	{
		container.addFields (TEXTAREACOUNT);
//		for (int i = 0; i < TEXTAREACOUNT; ++i)
//			container.add (new JTextArea ("test" + i));
//		for (int i = 0; i < container.getComponentCount (); ++i)
//			container.getComponent (i).setBackground (JTEXTAREA_BG_COLOR);
	}
}